

#include <cegfx/cenode.h>
#include <cegfx/inodeanimator.h>

ceNode::ceNode (NodeType type)
	: animator (0)
	, type (type)
	, cullingMode (CM_Cull)
	, range (0.0f, FLT_MAX)
{
	IQF_CONSTRUCT;
}


ceNode::~ceNode ()
{
}

IQF_IMPLEMENTATION_BEGIN (ceNode);
IQF_IMPLEMENTATION_END ();

void ceNode::BeginTransformation ()
{
	// nothing to do here
}

void ceNode::EndTransformation ()
{
	UpdateBoundingBox (&transform.GetMatrix (), &bbox);
}


void ceNode::SetTransform (const ceTransform& transform)
{
	this->transform = transform;
}

ceTransform& ceNode::GetTransform ()
{
	return transform;
}

const ceTransform& ceNode::GetTransform () const
{
	return transform;
}

void ceNode::UpdateBoundingBox (D3DXMATRIX* matrix, ceBoundingBox* bbox)
{
	static D3DXVECTOR4 t;
	bbox->Clear ();
	bbox->AddVector3 (matrix->_41, matrix->_42, matrix->_43);
	bbox->Update ();
}

ceBoundingBox& ceNode::GetBoundingBox () 
{
	return bbox;
}

const ceBoundingBox& ceNode::GetBoundingBox () const
{
	return bbox;
}



void ceNode::SetNodeAnimator (iNodeAnimator* animator)
{
	SAVE_SET(this->animator, animator);
}

iNodeAnimator* ceNode::GetNodeAnimator ()
{
	return animator;
}

const iNodeAnimator* ceNode::GetNodeAnimator () const
{
	return animator;
}

ceNode::NodeType ceNode::GetNodeType () const
{
	return type;
}


void ceNode::Update (const ceUpdateEnv& env)
{
	if (animator)
	{
		animator->UpdateNode (env, this);
	}
}


void ceNode::SetCullingMode (CullingMode cullingMode)
{
	this->cullingMode = cullingMode;
}

CullingMode ceNode::GetCullingMode () const
{
	return cullingMode;
}

void ceNode::SetRenderingRange (float max)
{
	range.SetMax (max * max);
}

void ceNode::SetRenderingRange (float min, float max)
{
	range.SetMin (min*min);
	range.SetMax (max*max);
}

const ceRange& ceNode::GetRenderingRange () const
{
	return range;
}

